<div class="widget">
	<div class="widget-header bg-blue">
		<i class="widget-icon icon-notebook"></i> 
		<span class="widget-caption"> 文章信息 </span>
		<div class="widget-buttons">
			<a href="javascript:void(0);" onclick="handlerCancel(this);" title="关闭"
				 data-toggle="dispose" data-refresh-table="#table-article"> <i class="fa fa-times"></i> </a> 
		</div>
	</div>
	<div class="widget-body">
		<!-- TODO 基本信息 -->
		<div class="widget radius-bordered">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 基本信息 </span>
			</div>
			<div class="widget-body editor-body-sm editor-body-article">
				<!-- dynamic data -->
			</div>
		</div>
	</div>
</div>

<!-- 提交表单 ========================================================= -->
<form id="editor-form-article" action="/miwawa/default/common/update" method="post" 
			name="com.app.miwawa.api.system.entity.Article">
			<input type="hidden" name="bean['status']" value="0">
			<input type="hidden" name="bean['invalid']" value="F">
			<input type="hidden" name="bean['pictures']" id="pictures">
</form>
  
    
<script type="text/javascript">
<!--
	var src = [];
	require(['domReady'], function(domReady){
		domReady(function () {
			loadData();
		});
	});
	
	var article; 
	function loadData(){
		article = jQuery("#table-article").data("selectedRow");
		jQuery(".editor-body-article").loadform("load", {
			templateId: "#view-article-template",
			templatePath: "/miwawa/content/system/content/article/template.html",
			templateData: article,
		
			onLoadSuccess: function(){
				require(['moment','jquery.plugin.form'],function(moment,form){
					form.tooltip("[data-toggle='tooltip']");
					form.datepicker('.date-selector',{format:'YYYY-MM-DD HH:mm'});
					form.chosen("#articleType").select("#articleType",null,function(chosen){
						
					});
					jQuery("#articleType").val(jQuery("#articlesType").val());
					getShops();				
					form.chosen("#shopId").select("#shopId",null,function(chosen){

					});
					jQuery("#shopId").val(jQuery("#shopsId").val());
					
					getAuthors();							
					jQuery("#authorId").val(jQuery("#authorsId").val());
					//jQuery("#contentPreview").html(jQuery("#content",'.form-editor-article').val());
					Preview();
					
					// 注册富文本编辑器控件
					form.summernote("#content",{
							toolbar:[    
							   ['fontsize', ['fontsize']] ,
							   ['fontname', ['fontname']],
							   ['style', ['bold', 'italic', 'underline', 'clear']],
							   ['color', ['color']],
							   ['picture', ['picture']],
							   ['link', ['link']],
							   ['table', ['table']],
							   ['para', ['ul', 'ol', 'paragraph','height']],
							   ['fullscreen', ['fullscreen']],
							   ['codeview', ['codeview']],
							   ['undo', ['undo']],
							   ['help', ['help']],
							],
							height:458,
							callbacks: {
					   		onImageUpload: function(files) {
					    		uploadFile(files[0]);
					    	}
					  	}
					});
					
					
				});
			}
		});
	}
	
	//上传文件
	function uploadFile(file){
		var data = new FormData();
	      data.append("file", file);
	      data.append("type", "image");
	      data.append("mode", "file");
	      data.append("group", "article");
	      data.append("notsaved", true);
	      
	  jQuery.ajaxsend({
		  url: "/miwawa/{dbname}/file/upload".replace("{dbname}", dbname),
		  data: data,
		  contentType: false,
	    processData: false,
		  success: function(file){
	    	jQuery("#content").summernote('insertImage', file.url ,function(image){
	    		image.css('width' , '100%');
	    	});
	    	src.push(file.url);
		  }
	  });
	}
	
	function getShops(){
		jQuery.ajaxsend({
        url:"/miwawa/default/common/search.json",
        data:{
            "entityClass":"com.app.miwawa.api.system.entity.view.ShopView",
            "and[0][operator]":"EQ",
            "and[0][fieldName]":"invalid",					// 删除标识
            "and[0][fieldValue]":"F",						// F=有效的<未删除>、T=无效的<已删除>
            "and[1][operator]":"EQ",
            "and[1][fieldName]":"status",					// 状态标识
            "and[1][fieldValue]":"0",						// 默认为0
            "and[2][operator]":"EQ",
            "and[2][fieldName]":"dbname",					    // 早教中心数据源
            "and[2][fieldValue]":dbname	// dbname
        },
        async:false,
        success : function(data) {
           var inner='';
           var dataList=data.rows;
           for(var i=0;i<dataList.length;i++){
               inner+='<option value="'+dataList[i].id +'">'+dataList[i].name+'</option>';
           }
           $("#shopId").html(inner);
        }
	   });
	}
	
	//获取员工列表
	function getAuthors(){
		jQuery.ajaxsend({
       url:"/miwawa/default/common/search.json",
       data:{
           "entityClass" : "com.app.miwawa.api.system.entity.view.Account",
           "and[0][operator]": "EQ",
           "and[0][fieldName]": "invalid",					// 删除标识
           "and[0][fieldValue]": "F",						// F=有效的<未删除>、T=无效的<已删除>
           "and[1][operator]": "EQ",
           "and[1][fieldName]": "status",					// 状态标识
           "and[1][fieldValue]": "0",						// 默认为0
           "and[2][operator]": "EQ",
           "and[2][fieldName]": "shopsid",			// 机构id
           "and[2][fieldValue]": $("#shopId").val()// 
       },
       async:false,
       success:function(data) {
          var inner='';
          var dataList=data.rows;
          for(var i=0;i<dataList.length;i++){
              inner+='<option value="'+dataList[i].id +'">'+dataList[i].name+'</option>';
          }
          $("#authorId").html(inner);
       }
		});
	  require(['jquery.plugin.form'],function(form){
			form.chosen("#authorId").select("#authorId",null,function(chosen){
				
			});
		});
	}
	
	function getSrc(){
/* 		var a= jQuery("#content",'.form-editor-article').val();
		var b= /src=\".*?\"/gi;
		var s = a.match(b);
		//alert(s);
		if(s != null){
			var reg = new RegExp("src=","g");
			var arr= s.toString().replace(reg,"");
			var reg2 = new RegExp("\"","g");
			var arr2= arr.replace(reg2,"");
			//alert(arr2);
			jQuery("#pictures",'#editor-form-article').val(arr2);
		}else{
			jQuery("#pictures",'#editor-form-article').val("http://www.honeykids.com.cn/miwawa/resources/photos/web/empty.png");
		} */
		jQuery("#pictures",'#editor-form-article').val($("#_img").attr("src"));
		return true;
	}
	
	function Preview(){	
		var contents = jQuery("#content",'.form-editor-article').val();
		jQuery("#contentPreview").html(contents);
		window.setTimeout("Preview()",100);
	}
	
	
//-->
</script>